package com.jifeng.sterilizer.controller;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.jifeng.sterilizer.service.HomeService;
import com.jifeng.sterilizer.vo.FarmListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.jifeng.sterilizer.entity.FarmEntity;
import com.jifeng.sterilizer.service.FarmService;
import com.jifeng.sterilizer.utils.PageUtils;
import com.jifeng.sterilizer.utils.R;


/**
 * 农场表
 *
 * @author jifeng
 * @email 1593140625@qq.com
 * @date 2020-07-26 15:15:14
 */
@RestController
@RequestMapping("sterilizer/farm")
public class FarmController {
    @Autowired
    private FarmService farmService;

    // 根据名称模糊查询农场列表 PC
    @GetMapping("/pc/name/list")
    public R getFarmListByName(@RequestParam Map<String, Object> params) {
        R rs = farmService.getFarmListByName(params);
        return rs;
    }

    /**
     * 列表
     */
//    @GetMapping("/list")
//    public R list(@RequestParam Map<String, Object> params){
//        PageUtils page = farmService.queryPage(params);
//
//        return R.ok().put("page", page);
//    }

    /**
     * 获取农场列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        R rs = farmService.getFarmList(params);

        return rs;
    }

    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        FarmEntity farm = farmService.getById(id);

        return R.ok().put("farm", farm);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody FarmEntity farm) {
        farmService.save(farm);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody FarmEntity farm) {
        farmService.updateById(farm);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        farmService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
